function ownKeys(t, e) {
    var r, n = Object.keys(t);
    return Object.getOwnPropertySymbols && (r = Object.getOwnPropertySymbols(t), e && (r = r.filter(function(e) {
        return Object.getOwnPropertyDescriptor(t, e).enumerable;
    })), n.push.apply(n, r)), n;
}

function _objectSpread(t) {
    for (var e = 1; e < arguments.length; e++) {
        var r = null != arguments[e] ? arguments[e] : {};
        e % 2 ? ownKeys(r, !0).forEach(function(e) {
            _defineProperty(t, e, r[e]);
        }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(r)) : ownKeys(r).forEach(function(e) {
            Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(r, e));
        });
    }
    return t;
}

function _defineProperty(e, t, r) {
    return t in e ? Object.defineProperty(e, t, {
        value: r,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = r, e;
}

function _classCallCheck(e, t) {
    if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}

function _defineProperties(e, t) {
    for (var r = 0; r < t.length; r++) {
        var n = t[r];
        n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), 
        Object.defineProperty(e, n.key, n);
    }
}

function _createClass(e, t, r) {
    return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = createFieldsStore;

var FieldsStore = function() {
    function t() {
        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
        _classCallCheck(this, t), this.fields = e;
    }
    return _createClass(t, [ {
        key: "setFields",
        value: function(e) {
            Object.assign(this.fields, e);
        }
    }, {
        key: "updateFields",
        value: function(e) {
            this.fields = e;
        }
    }, {
        key: "clearField",
        value: function(e) {
            delete this.fields[e];
        }
    }, {
        key: "getValueFromFields",
        value: function(e, t) {
            e = t[e];
            return e && "value" in e ? e.value : e.initialValue;
        }
    }, {
        key: "getAllFieldsName",
        value: function() {
            var e = this.fields;
            return e ? Object.keys(e) : [];
        }
    }, {
        key: "getField",
        value: function(e) {
            return _objectSpread({}, this.fields[e], {
                name: e
            });
        }
    }, {
        key: "getFieldValuePropValue",
        value: function(e) {
            var t = e.name, e = e.valuePropName, t = this.getField(t);
            return _defineProperty({}, e, "value" in t ? t.value : t.initialValue);
        }
    }, {
        key: "getFieldValue",
        value: function(e) {
            return this.getValueFromFields(e, this.fields);
        }
    }, {
        key: "getFieldsValue",
        value: function(e) {
            var r = this;
            return (e || this.getAllFieldsName()).reduce(function(e, t) {
                return e[t] = r.getFieldValue(t), e;
            }, {});
        }
    }, {
        key: "resetFields",
        value: function(e) {
            var n = this.fields;
            return (e || this.getAllFieldsName()).reduce(function(e, t) {
                var r = n[t];
                return r && (e[t] = r.initialValue), e;
            }, {});
        }
    } ]), t;
}();

function createFieldsStore(e) {
    return new FieldsStore(e);
}